#include <iostream>
#include <unordered_map>
#include <sstream>

using namespace std;

class Solution {
public:
    bool wordPattern(string pattern, string str) {
        unordered_map<string, int> map1;
        unordered_map<char, int> map2;
        istringstream is(str);
        string s;
        for (int i = 0; i < pattern.size(); i++) {
            string s;
            is >> s;
            if (s.size() == 0) {
                return false;
            }
            if (map1[s] != map2[pattern[i]]) {
                return false;
            } else {
                map1[s] = i + 1;
                map2[pattern[i]] = i + 1;
            }
        }
        if (is >> s) {
            return false;
        }
        return true;
    }
};

int main() {
    Solution solution;
    solution.wordPattern("abba", "dog cat cat fish");
    return 0;
}